import React, { Component } from 'react'

export default class Count extends Component {
  incrementCount=()=>{
    const {value}=this.selectNumber
    this.props.jia(value*1)
  }
  decrementCount=()=>{
    const {value}=this.selectNumber
    this.props.jian(value*1)
  }
  incrementCountIfOdd=()=>{
    const {value}=this.selectNumber
    if(this.props.count%2===0){
      this.props.jia(value*1)
    }
  }
  incrementCountAsync=()=>{
    const {value}=this.selectNumber
    this.props.jiasync(value*1,1000)
  }
  render() {
    console.log('UI组件接收到容器组件的数据是',this.props);
    return (
      <div>
        <h1>当前求和为:{this.props.count}</h1>
        <select ref={c=>this.selectNumber=c}>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
        </select>&nbsp;
        <button onClick={this.incrementCount}>+</button>&nbsp;
        <button onClick={this.decrementCount}>-</button>&nbsp;
        <button onClick={this.incrementCountIfOdd}>偶数时再加</button>
        <button onClick={this.incrementCountAsync}>等待完再加</button>
      </div>
    )
  }
}
